<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java调用C语言SDK完全指南</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
            border: 2px solid transparent;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            border-color: #667eea;
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 12px;
            overflow: hidden;
            position: relative;
        }
        
        .code-header {
            background: #2d2d2d;
            padding: 8px 16px;
            font-size: 14px;
            color: #888;
            border-bottom: 1px solid #444;
        }
        
        .code-content {
            padding: 16px;
            overflow-x: auto;
            font-family: 'Consolas', 'Monaco', monospace;
            line-height: 1.6;
        }
        
        .step-number {
            width: 40px;
            height: 40px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
            flex-shrink: 0;
        }
        
        .comparison-card {
            background: white;
            border-radius: 16px;
            padding: 24px;
            transition: all 0.3s ease;
            border: 2px solid transparent;
        }
        
        .comparison-card:hover {
            border-color: #667eea;
            transform: scale(1.02);
        }
        
        .method-badge {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 14px;
            font-weight: 500;
            display: inline-block;
        }
        
        .highlight-text {
            background: linear-gradient(to right, #667eea, #764ba2);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-weight: 600;
        }
        
        .section-divider {
            height: 2px;
            background: linear-gradient(to right, transparent, #667eea, #764ba2, transparent);
            margin: 48px 0;
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fade-in {
            animation: fadeInUp 0.6s ease-out;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 32px 0;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white">
        <div class="container mx-auto px-6 py-20">
            <div class="max-w-4xl mx-auto text-center animate-fade-in">
                <h1 class="text-5xl font-bold mb-6">Java调用C语言SDK完全指南</h1>
                <p class="text-xl opacity-90 leading-relaxed">
                    探索Java与C语言交互的三种主流方案，从底层JNI到便捷的JNA，助您选择最适合的技术路径
                </p>
                <div class="mt-8 flex justify-center space-x-6">
                    <div class="flex items-center">
                        <i class="fas fa-code text-2xl mr-2"></i>
                        <span>深度集成</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-rocket text-2xl mr-2"></i>
                        <span>高性能</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-shield-alt text-2xl mr-2"></i>
                        <span>生产可用</span>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12">
        <!-- Overview Section -->
        <div class="max-w-6xl mx-auto mb-16">
            <div class="bg-white rounded-2xl shadow-xl p-8 animate-fade-in">
                <h2 class="text-3xl font-bold mb-6 text-gray-800">
                    <i class="fas fa-layer-group mr-3 text-purple-600"></i>
                    技术方案概览
                </h2>
                <div class="mermaid">
                    graph TD
                        A[Java应用程序] --> B{选择调用方式}
                        B --> C[JNI<br/>Java Native Interface]
                        B --> D[JNA<br/>Java Native Access]
                        B --> E[Process<br/>进程调用]
                        C --> F[高性能<br/>深度集成]
                        D --> G[简单易用<br/>快速开发]
                        E --> H[独立进程<br/>松耦合]
                        style A fill:#667eea,stroke:#fff,color:#fff
                        style B fill:#764ba2,stroke:#fff,color:#fff
                        style C fill:#e0e7ff,stroke:#667eea
                        style D fill:#e0e7ff,stroke:#667eea
                        style E fill:#e0e7ff,stroke:#667eea
                </div>
            </div>
        </div>

        <!-- Method 1: JNI -->
        <div class="max-w-6xl mx-auto mb-16">
            <div class="bg-white rounded-2xl shadow-xl overflow-hidden card-hover">
                <div class="hero-gradient p-6">
                    <h2 class="text-3xl font-bold text-white flex items-center">
                        <span class="method-badge bg-white text-purple-700 mr-4">方案一</span>
                        使用 JNI（Java Native Interface）
                    </h2>
                </div>
                
                <div class="p-8">
                    <p class="text-lg text-gray-700 mb-8 leading-relaxed">
                        JNI 是 Java 官方提供的与本地代码（C/C++）交互的方式，适用于<span class="highlight-text">高性能需求</span>或者需要调用<span class="highlight-text">底层系统 API</span> 的场景。
                    </p>

                    <!-- Steps -->
                    <div class="space-y-6">
                        <!-- Step 1 -->
                        <div class="flex items-start space-x-4">
                            <div class="step-number">1</div>
                            <div class="flex-1">
                                <h4 class="text-xl font-semibold mb-3">编写 Java 代码声明本地方法</h4>
                                <div class="code-block">
                                    <div class="code-header">NativeLib.java</div>
                                    <pre class="code-content"><code>public class NativeLib {
    // 声明本地方法
    public native int add(int a, int b);
    
    // 加载动态库
    static {
        System.loadLibrary("mylib"); // 加载 mylib.dll 或 mylib.so
    }

    public static void main(String[] args) {
        NativeLib lib = new NativeLib();
        System.out.println("Result: " + lib.add(3, 5));
    }
}</code></pre>
                                </div>
                            </div>
                        </div>

                        <!-- Step 2 -->
                        <div class="flex items-start space-x-4">
                            <div class="step-number">2</div>
                            <div class="flex-1">
                                <h4 class="text-xl font-semibold mb-3">编译 Java 代码</h4>
                                <div class="code-block">
                                    <div class="code-header">Terminal</div>
                                    <pre class="code-content"><code>javac NativeLib.java</code></pre>
                                </div>
                            </div>
                        </div>

                        <!-- Step 3 -->
                        <div class="flex items-start space-x-4">
                            <div class="step-number">3</div>
                            <div class="flex-1">
                                <h4 class="text-xl font-semibold mb-3">生成 C 头文件</h4>
                                <div class="code-block">
                                    <div class="code-header">Terminal</div>
                                    <pre class="code-content"><code>javah -jni NativeLib</code></pre>
                                </div>
                                <p class="mt-3 text-gray-600">生成的头文件内容：</p>
                                <div class="code-block mt-2">
                                    <div class="code-header">NativeLib.h</div>
                                    <pre class="code-content"><code>/* DO NOT EDIT THIS FILE - it is machine generated */
#include &lt;jni.h&gt;
#ifndef _Included_NativeLib
#define _Included_NativeLib
#ifdef __cplusplus
extern "C" {
#endif
JNIEXPORT jint JNICALL Java_NativeLib_add(JNIEnv *, jobject, jint, jint);
#ifdef __cplusplus
}
#endif
#endif</code></pre>
                                </div>
                            </div>
                        </div>

                        <!-- Step 4 -->
                        <div class="flex items-start space-x-4">
                            <div class="step-number">4</div>
                            <div class="flex-1">
                                <h4 class="text-xl font-semibold mb-3">实现 C 代码</h4>
                                <div class="code-block">
                                    <div class="code-header">NativeLib.c</div>
                                    <pre class="code-content"><code>#include "NativeLib.h"
#include &lt;stdio.h&gt;

JNIEXPORT jint JNICALL Java_NativeLib_add(JNIEnv *env, jobject obj, jint a, jint b) {
    return a + b;
}</code></pre>
                                </div>
                            </div>
                        </div>

                        <!-- Step 5 -->
                        <div class="flex items-start space-x-4">
                            <div class="step-number">5</div>
                            <div class="flex-1">
                                <h4 class="text-xl font-semibold mb-3">编译 C 代码生成动态库</h4>
                                <div class="grid md:grid-cols-2 gap-4">
                                    <div>
                                        <p class="font-semibold mb-2 text-gray-700">
                                            <i class="fab fa-windows mr-2"></i>Windows (MinGW)
                                        </p>
                                        <div class="code-block">
                                            <div class="code-header">Terminal</div>
                                            <pre class="code-content"><code>gcc -shared -o mylib.dll -I"%JAVA_HOME%\include" -I"%JAVA_HOME%\include\win32" NativeLib.c</code></pre>
                                        </div>
                                    </div>
                                    <div>
                                        <p class="font-semibold mb-2 text-gray-700">
                                            <i class="fab fa-linux mr-2"></i>Linux/macOS
                                        </p>
                                        <div class="code-block">
                                            <div class="code-header">Terminal</div>
                                            <pre class="code-content"><code>gcc -shared -o libmylib.so -fPIC -I"$JAVA_HOME/include" -I"$JAVA_HOME/include/linux" NativeLib.c</code></pre>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- Step 6 -->
                        <div class="flex items-start space-x-4">
                            <div class="step-number">6</div>
                            <div class="flex-1">
                                <h4 class="text-xl font-semibold mb-3">运行 Java 程序</h4>
                                <div class="code-block">
                                    <div class="code-header">Terminal</div>
                                    <pre class="code-content"><code>java -Djava.library.path=. NativeLib</code></pre>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="section-divider"></div>

        <!-- Method 2: JNA -->
        <div class="max-w-6xl mx-auto mb-16">
            <div class="bg-white rounded-2xl shadow-xl overflow-hidden card-hover">
                <div class="hero-gradient p-6">
                    <h2 class="text-3xl font-bold text-white flex items-center">
                        <span class="method-badge bg-white text-purple-700 mr-4">方案二</span>
                        使用 JNA（Java Native Access）
                    </h2>
                </div>
                
                <div class="p-8">
                    <p class